package com.athuiju.eduservice.controller.front;

import com.athuiju.commonutils.R;
import com.athuiju.eduservice.entity.EduCourse;
import com.athuiju.eduservice.entity.Teacher;
import com.athuiju.eduservice.service.EduCourseService;
import com.athuiju.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")

public class IndexfrontController {
@Autowired
    private EduCourseService courseService;
@Autowired
    private TeacherService teacherService;
//查询前八条热门课程,铲鲟前四名讲师
    @GetMapping("index")
    public R index(){
        //查询前八条热门课程
        QueryWrapper<EduCourse>wrapper=new QueryWrapper<>();
        wrapper.orderByAsc("id");
        wrapper.last("limit 8");
        List<EduCourse>eduList =courseService.list(wrapper);
        //查询前四条名师
        QueryWrapper<Teacher>wrapperTeacher=new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<Teacher>teacherList=teacherService.list(wrapperTeacher);
        return R.ok().data("eduList",eduList).data("teacherList",teacherList);

    }

}
